package cn.tonyandmoney.baidu.asr.service

import android.app.Service
import android.content.Intent
import android.os.IBinder
import cn.tonyandmoney.baidu.asr.controller.Recognizer
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.info

/**
 * Created by niantuo on 2018/2/8.
 * 百度语音识别的服务
 */
class RecognizerService : Service(), AnkoLogger {

    private val mRecognizer: Recognizer by lazy { Recognizer(this) }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        info("onStartCommand ")
        return Service.START_STICKY
    }

    override fun onBind(intent: Intent?): IBinder? {
        info("onBind ")
        return mRecognizer.asBinder()
    }

    override fun onUnbind(intent: Intent?): Boolean {
        info("onUnbind ")
        stopSelf()
        return true
    }

    override fun onRebind(intent: Intent?) {
        super.onRebind(intent)
        info("onRebind ")
    }

    override fun onDestroy() {
        super.onDestroy()
        mRecognizer.release()
        info("onDestroy")
    }
}